package gazzera.node.core;

import gazzera.node.core.messages.*;


/**
 * Note that DataPumps are run in separated threads so you're not allowed to 
 * store and access any of the core components and objects.
 * Also note that in the finished method you should only perform local resource
 * deallocation & cleaning, do not communicate with other core or plugin components.
 * An automatic DataPumpFinished message will be delivered for this.
 *
 */
public interface DataPumpSource
{
    /**
     * Initialize this datapumps (ie. open any resource to be send)
     * @throws Exception
     */
    void init() throws Exception;
    /**
     * Prepare the next message to be send
     * @return the message to be send or null if the datapump has finished
     * @throws Exception
     */
    public Message next() throws Exception;
    
    /**
     * The datapump has finished. This method should close any resource used before.
     * @param interrupted whethere the pump was closed cleanly (becouse next() returned false) or not (by an external messate or exception)
     * @throws Exception
     */
    void finished(boolean interrupted) throws Exception;
}
